local skel = fk.CreateSkill {
  name = "emo__shenghu",
}

Fk:loadTranslationTable{
  ["emo__shenghu"] = "圣护",
  [":emo__shenghu"] = "①游戏开始时或回合开始时，若你未发动此技能，你可以令一名其他角色获得“圣护”标记和1点护甲。<br>"..
  "②“圣护”角色受到【杀】伤害后，摸一张并令你获得此【杀】，其他伤害转移给你。<br>"..
  "③你使用【杀】无法响应，且对“圣护”角色外造成伤害+1。",

  ["#emo__shenghu-choose"] = "圣护：令一名其他角色获得“圣护”标记（建议选队友）",
  ["@@emo__shenghu"] = "圣护",
}

local can_trigger = function(self, event, target, player, data)
  return player:hasSkill(skel.name) and player:usedSkillTimes(skel.name, Player.HistoryGame) == 0
end

local on_cost = function(self, event, target, player, data)
  local tos = player.room:askToChoosePlayers(player, {
    min_num = 1, max_num = 1, targets = player.room:getOtherPlayers(player), skill_name = skel.name,
    prompt = "#emo__shenghu-choose",
  })
  if #tos > 0 then
    event:setCostData(self, {tos = tos})
    return true
  end
end

local on_use = function (self, event, target, player, data)
  local room = player.room
  local to = event:getCostData(self).tos[1]
  room:setPlayerMark(player, skel.name, to.id)
  room:addPlayerMark(to, "@@emo__shenghu")
  room:changeShield(to, 1)
end

skel:addEffect(fk.GameStart, {
  anim_type = "support",
  can_trigger = can_trigger,
  on_cost = on_cost,
  on_use = on_use,
})

skel:addEffect(fk.TurnStart, {
  anim_type = "support",
  can_trigger = can_trigger,
  on_cost = on_cost,
  on_use = on_use,
})

skel:addEffect(fk.Damaged, {
  anim_type = "support",
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(skel.name) and data.card and data.card.trueName == "slash" and target.id == player:getMark(skel.name)
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    target:drawCards(1, skel.name)
    if player:isAlive() then
      room:obtainCard(player, room:getSubcardsByRule(data.card, {Card.Processing}), true, fk.ReasonPrey, player, skel.name)
    end
  end,
})

skel:addEffect(fk.DamageInflicted, {
  anim_type = "defensive",
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(skel.name) and not (data.card and data.card.trueName == "slash") and target.id == player:getMark(skel.name)
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    room:doIndicate(target, {player})
    local n = data.damage
    data:preventDamage()
    room:damage{
      from = data.from,
      to = player,
      damage = n,
      damageType = data.damageType,
      skillName = data.skillName,
      chain = data.chain,
      card = data.card,
    }
  end,
})

skel:addEffect(fk.CardUsing, {
  anim_type = "offensive",
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(skel.name) and target == player and data.card.trueName == "slash"
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    data.disresponsiveList = table.simpleClone(player.room.players)
    data.extra_data = data.extra_data or {}
  end,
})

skel:addEffect(fk.DamageCaused, {
  anim_type = "drawcard",
  can_refresh = function (self, event, target, player, data)
    return player:hasSkill(skel.name) and target == player and data.card and data.card.trueName == "slash"
    and data.to.id ~= player:getMark(skel.name)
  end,
  on_refresh = function (self, event, target, player, data)
    data:changeDamage(1)
  end,
})

skel:addLoseEffect(function (self, player, is_death)
  local to = player.room:getPlayerById(player:getMark(skel.name))
  if to then
    player.room:removePlayerMark(to, "@@emo__shenghu")
  end
end)

return skel
